/*
//  Copyright © 2014 Allen County Public Library.

  //        ACPL Mobile is free software: This program is distributed and you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.  ACPL Mobile is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY, including without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with ACPL Mobile. If not, see http://www.gnu.org/licenses/.
 * Author: James Harpe
 * 
 * Description: This class responds to the "Boot Completed" intent, and starts alarms for the account and event
 * 				notification services. 
 * 
 */

package us.in.lib.acpl.Mobile_ACPL.service;

import us.in.lib.acpl.Mobile_ACPL.service.account.AccountOnAlarmReceiver;
import us.in.lib.acpl.Mobile_ACPL.service.event.EventOnAlarmReceiver;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.SystemClock;

public class OnBootReceiver extends BroadcastReceiver {
	private static final int ACCOUNT_PERIOD = 86400000; // 1 day
	private static final int EVENT_PERIOD = 600000; // 10 minutes

	@Override
	public void onReceive(Context context, Intent intent) {
		System.out.print("received");
		AlarmManager mgr = (AlarmManager) context
				.getSystemService(Context.ALARM_SERVICE);
		Intent i = new Intent(context, AccountOnAlarmReceiver.class);
		PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);

		mgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
				SystemClock.elapsedRealtime() + 60000, ACCOUNT_PERIOD, pi);

		mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
		i = new Intent(context, EventOnAlarmReceiver.class);
		pi = PendingIntent.getBroadcast(context, 0, i, 0);

		mgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
				SystemClock.elapsedRealtime() + 60000, EVENT_PERIOD, pi);
	}
}